package com.threadpool.mythread.case01;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Author 李李李
 * @2020/4/25 22:28
 *
 * 加法计数器
 *
 */
public class Case05 {
    public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7,()->{
            System.out.println("七颗龙珠集齐了，召唤神龙成功！");
        });

        for(int i =  1;i <= 7 ;i++){
            final int temp = i;
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + "已经收集到了"+ temp +"颗龙珠！");
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
